package com.link.wseller.http;

import lombok.Data;

import java.io.Serializable;

@Data
public class JsonResult implements Serializable {

    /**
     * 反馈信息
     */
    private String msg;

    /**
     * 响应码
     */
    private int code;


    /**
     * 反馈数据
     */
    private Object data;


    protected JsonResult(String msg) {
        this.code = 500;
        this.msg = msg;
    }

    protected JsonResult(boolean success, Object data) {
        this.code = success ? 200 : 500;
        this.data = data;
    }

    protected JsonResult(boolean success, Object data, int code) {
        this(success, data);
        this.code = code;
    }

    public static JsonResult success() {
        return success(null);
    }

    public static JsonResult success(Object data) {
        return new JsonResult(true, data);
    }

    public static JsonResult created(Object data) {
        return new JsonResult(true, data, 200);
    }

    public static JsonResult error(String msg) {
        return new JsonResult(msg);
    }
}
